#使用示例
#source ./src/set_env_mindie_all.sh ./src/all_config.yaml
#取消某环境需要 unset

if [ -z "$CONFIG_FILE" ]; then
	export CONFIG_FILE=$1
fi
source ./src/read_config.sh

export RANKTABLEFILE=$RANK_TABLE_FILE
export RANK_TABLE_FILE=$RANK_TABLE_FILE
if [ -z "$RANKTABLEFILE" ]; then
	echo "RANKTABLEFILE should be set"
	exit 1
fi
if [ -z "$MIES_CONTAINER_IP" ]; then
	echo "MIES_CONTAINER_IP should be set"
	exit 1
fi
#开启查看服务具体报错
export MINDIE_LOG_TO_STDOUT=$MINDIE_LOG_TO_STDOUT

export PYTORCH_NPU_ALLOC_CONF=$PYTORCH_NPU_ALLOC_CONF
export HCCL_CONNECT_TIMEOUT=$HCCL_CONNECT_TIMEOUT
export HCCL_DETERMINISTIC=$HCCL_DETERMINISTIC
export NPU_MEMORY_FRACTION=$NPU_MEMORY_FRACTION
export HCCL_EXEC_TIMEOUT=$HCCL_EXEC_TIMEOUT
export OMP_NUM_THREADS=$OMP_NUM_THREADS
export ATB_WORKSPACE_MEM_ALLOC_ALG_TYPE=$ATB_WORKSPACE_MEM_ALLOC_ALG_TYPE

#更新
export INF_NAN_MODE_ENABLE=1
unset ASCEND_LAUNCH_BLOCKING
export ATB_LAYER_INTERNAL_TENSOR_REUSE=1
export ATB_OPENATION_EXECUTE_ASYNC=1
export ATB_CONVERT_NCHW_TO_ND=1
export ATB_CONTEXT_WORKSPACE_SIZE=0
export ATB_LAUNCH_KERNEL_WITH_TILING=1
export HCCL_RDMA_PCIE_DIRECT_POST_NOSTRICT=TRUE

export HCCL_OP_EXPANSION_MODE=$HCCL_OP_EXPANSION_MODE
export CPU_AFFINITY_CONF=$CPU_AFFINITY_CONF
export TASK_QUEUE_ENABLE=$TASK_QUEUE_ENABLE
export BIND_CPU=$BIND_CPU
if $A3_SUPER_NODE; then
	export ATB_WORKSPACE_MEM_ALLOC_GLOBAL=$A3_ATB_WORKSPACE_MEM_ALLOC_GLOBAL
	export ATB_LLM_ENABLE_AUTO_TRANSPOSE=$A3_ATB_LLM_ENABLE_AUTO_TRANSPOSE
	export MASTER_IP=$ALL_IP_0_1
	# 服务化调度日志
	#export MINDIE_LLM_BENCHMARK_ENABLE=2
	# 异步发射
	export MINDIE_ASYNC_SCHEDULING_ENABLE=$A3_MINDIE_ASYNC_SCHEDULING_ENABLE
else
	export ATB_LLM_HCCL_ENABLE=$ATB_LLM_HCCL_ENABLE
	export ATB_LLM_COMM_BACKEND=$ATB_LLM_COMM_BACKEND
	export WORLD_SIZE=$WORLD_SIZE
fi

# unset ATB_WORKSPACE_MEM_ALLOC_ALG_TYPE
# unset CPU_AFFINITY_CONF
# unset TASK_QUEUE_ENABLE
# unset BIND_CPU
# unset HCCL_OP_EXPANSION_MODE

echo RANKTABLEFILE:$RANKTABLEFILE
echo RANK_TABLE_FILE:$RANK_TABLE_FILE
echo MIES_CONTAINER_IP: $MIES_CONTAINER_IP